package com.rogo.rogobox.models
{
	import com.rogo.mvc.sub.proxy.Proxy;
	import com.rogo.rogobox.AppFacade;
	import com.rogo.rogobox.models.vo.FriendsReqVO;
	import com.sina.microblog.events.MicroBlogErrorEvent;
	import com.sina.microblog.events.MicroBlogEvent;
	
	/**
	 * 1.3 用户接口
	 * 
	 * @see http://open.weibo.com/wiki/API文档
	 * 
	 * @author rogo
	 */	
	public class UserProxy extends Proxy
	{
		public function UserProxy()
		{
			super(NAME);
		}
		
		//--------------------------------------------------------------------------
		//
		//  Constants
		//
		//--------------------------------------------------------------------------
		
		public static const NAME:String = 'userProxy';
		
		//--------------------------------------------------------------------------
		//
		//  Varaibles
		//
		//--------------------------------------------------------------------------
		
		private var blog:BlogDelegate;
		
		//--------------------------------------------------------------------------
		//
		//  Overridden Methods
		//
		//--------------------------------------------------------------------------
		
		override public function onRegister():void
		{
			blog = BlogDelegate.getInstance();
			blog.addEventListener(MicroBlogEvent.LOAD_USER_INFO_RESULT, blog_loadUserInfoResultHandler);
			blog.addEventListener(MicroBlogErrorEvent.LOAD_USER_INFO_ERROR, blog_loadUserInfoErrorHandler);
			blog.addEventListener(MicroBlogEvent.LOAD_FRIENDS_INFO_RESULT, blog_loadFriendsResultHandler);
			blog.addEventListener(MicroBlogErrorEvent.LOAD_FRIENDS_INFO_ERROR, blog_loadFriendsErrorHandler);
			blog.addEventListener(MicroBlogEvent.LOAD_FOLLOWERS_INFO_RESULT, blog_loadFollowersResultHandler);
			blog.addEventListener(MicroBlogErrorEvent.LOAD_FOLLOWERS_INFO_ERROR, blog_loadFollowersErrorHandler);
		}
		
		//--------------------------------------------------------------------------
		//
		//  Methods
		//
		//--------------------------------------------------------------------------
		
		public function loadUserInfo(id:String):void
		{
			sendNotification(AppFacade.LOADING_START);
			blog.loadUserInfo(null, id);
		}
		
		public function loadFriends(vo:FriendsReqVO):void
		{
			blog.loadFriendsInfo(vo.user, vo.userID, vo.screenName, vo.cursor, vo.count);
		}
		
		public function loadFollower(vo:FriendsReqVO):void
		{
			blog.loadFollowersInfo(vo.user, vo.userID, vo.screenName, vo.cursor, vo.count);
		}
		
		//--------------------------------------------------------------------------
		//
		//  Event Handlers
		//
		//--------------------------------------------------------------------------
		
		private function blog_loadUserInfoResultHandler(e:MicroBlogEvent):void
		{
			sendNotification(AppFacade.LOADING_END);
			sendNotification(AppFacade.USER_PROFILE_RESULT, e.result);
		}
		
		private function blog_loadUserInfoErrorHandler(e:MicroBlogErrorEvent):void
		{
			sendNotification(AppFacade.LOADING_END);
		}
		
		private function blog_loadFriendsResultHandler(e:MicroBlogEvent):void
		{
			sendNotification(AppFacade.LOAD_FRIENDS_RESULT, e.result);
		}
		
		private function blog_loadFriendsErrorHandler(e:MicroBlogErrorEvent):void
		{
		}
		
		private function blog_loadFollowersResultHandler(e:MicroBlogEvent):void
		{
			sendNotification(AppFacade.LOAD_FOLLOWER_RESULT, e.result);
		}
		
		private function blog_loadFollowersErrorHandler(e:MicroBlogErrorEvent):void
		{
		}
		
	}
}